1 module hip.api.input.core;
2 public import hip.api.input.mouse;
3 public import hip.api.input.keyboard;
4 public import hip.api.input.gamepad;
5 public import hip.api.renderer.viewport;
6 
7 interface IHipInput
8 {
9     bool isKeyPressed(char key, uint id = 0);
10     bool isKeyJustPressed(char key, uint id = 0);
11     bool isKeyJustReleased(char key, uint id = 0);
12     float getKeyDownTime(char key, uint id = 0);
13     float getKeyUpTime(char key, uint id = 0);
14 
15     //Mouse/Touch functions
16     ubyte getMulticlickCount(HipMouseButton btn = HipMouseButton.any, uint id = 0);
17     bool isDoubleClicked(HipMouseButton btn = HipMouseButton.any, uint id = 0);
18     bool isMouseButtonPressed(HipMouseButton btn = HipMouseButton.any, uint id = 0);
19     bool isMouseButtonJustPressed(HipMouseButton btn = HipMouseButton.any, uint id = 0);
20     bool isMouseButtonJustReleased(HipMouseButton btn = HipMouseButton.any, uint id = 0);
21 
22     ///Gets Raw touch/mouse position
23     float[2] getTouchPosition(uint id = 0);
24     ///Gets normallized to the window touch/mouse position
25     float[2] getNormallizedTouchPosition(uint id = 0);
26     alias getNormallizedMousePosition = getNormallizedTouchPosition;
27     ///Gets touch position in world transform. The world transform can both be based in Viewport argument, if none is passed, it is based on the currently active viewport
28     float[2] getWorldTouchPosition(uint id = 0, Viewport vp = null);
29     alias getWorldMousePosition = getWorldTouchPosition;
30     float[2] getTouchDeltaPosition(uint id=0);
31     float[3] getScroll(uint id=0);
32     //Gamepad Functions
33     ubyte getGamepadCount();
34     AHipGamepad getGamepad(ubyte id = 0);
35     float[3] getAnalog(HipGamepadAnalogs analog, ubyte id = 0);
36     bool isGamepadButtonPressed(HipGamepadButton btn, ubyte id = 0);
37     bool isGamepadButtonJustPressed(HipGamepadButton btn, ubyte id = 0);
38     bool isGamepadButtonJustReleased(HipGamepadButton btn, ubyte id = 0);
39 
40 
41     bool areGamepadButtonsPressed(scope HipGamepadButton[] btn, ubyte id = 0);
42     bool areGamepadButtonsJustPressed(scope HipGamepadButton[] btn, ubyte id = 0);
43     bool areGamepadButtonsJustReleased(scope HipGamepadButton[] btn, ubyte id = 0);
44     
45     bool setGamepadVibrating(float vibrationPower, float time, ubyte id = 0);
46     float getGamepadBatteryStatus(ubyte id = 0);
47     bool isGamepadWireless(ubyte id = 0);
48 
49     alias isTouchPressed = isMouseButtonPressed;
50     alias isTouchJustPressed = isMouseButtonJustPressed;
51     alias isTouchJustReleased = isMouseButtonJustReleased;
52 }
53 
54 interface IHipInputListener
55 {
56     const(HipButton)* addKeyboardListener(HipKey key, HipInputAction action,
57     HipButtonType type = HipButtonType.down,
58     AutoRemove remove = AutoRemove.no);
59 
60     const(HipButton)* addTouchListener(HipMouseButton btn, HipInputAction action,
61     HipButtonType type = HipButtonType.down,
62     AutoRemove remove = AutoRemove.no);
63 
64     const(ScrollListener)*  addScrollListener(HipScrollAction onScoll,
65     AutoRemove remove = AutoRemove.no);
66 
67     const(TouchMoveListener)* addTouchMoveListener(HipTouchMoveAction onMove,
68     AutoRemove remove = AutoRemove.no);
69 
70     bool removeKeyboardListener(const(HipButton)* button);
71     bool removeTouchListener(const(HipButton)* btn);
72     bool removeScrollListener(const(ScrollListener)*);
73     bool removeTouchMoveListener(const(TouchMoveListener)*);
74 }
75 
76 private __gshared
77 {
78     IHipInput _input;
79     IHipInputListener _inputListener;
80 }
81 void setHipInput(IHipInput input){_input = input;}
82 void setHipInputListener(IHipInputListener inputListener){_inputListener = inputListener;}
83 pragma(inline, true)
84 {
85     IHipInput HipInput(){return _input;}
86     IHipInputListener HipInputListener(){return _inputListener;}
87 }